<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
	<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
	<title>员工管理</title>
	<script type="text/javascript" src="../../js/boot.js"></script>
</head>

<body>
	<div class="mini-splitter" style="width: 100%; height: 100%;">
		<div size="240" showCollapseButton="true">
			<div class="mini-fit">
				<ul id="pageTree" class="mini-tree" style="width: 100%;" showTreeIcon="true" allowDrag="true" allowDrop="true" textField="departName"
					idField="departID" resultAsTree="false">
				</ul>
			</div>
		</div>

		<div showCollapseButton="true">
			<fieldset id="fd1" style="width: 97%; margin-bottom: 10px;">
				<legend><span>查询条件</span></legend>
				<div id="queryForm" class="fieldset-body">
					<table class="form-table" border="0" cellpadding="0" cellspacing="0">
						<tr>
							<td class="form-label">
								<span>姓名：</span>
								<input name="userName" class="mini-textbox" style="width: 150px" />
								<input name="userName_link" value="like" class="mini-hidden" />
								<span>工号：</span>
								<input name="workNo" class="mini-textbox" style="width: 150px" />
								<span>在职状态：</span>
								<input name="status" class="mini-combobox" data="CONST.get('onJobState', 'all')" textField="text" valueField="id"
									style="width: 100px">
								<a style="margin: 0 0 0 0;" class="mini-button" iconCls="icon-search" onclick="search()">查询</a>
								<a style="margin: 0 0 0 0;" class="mini-button" iconCls="icon-new" onclick="input()">新增</a>
								<a style="margin: 0 0 0 0;" class="mini-button" iconCls="icon-edit" onclick="edit()">修改</a>
							</td>
						</tr>
					</table>
				</div>
			</fieldset>

			<div  class="mini-fit" style="height: 100%;" >
				<div id="datagrid" class="mini-datagrid" style="width:100%;height:100%;" url="" idField="id" allowResize="true" pageSize="20"  allowCellSelect="true" multiSelect="true"
					 editNextOnEnterKey="true" editNextRowCell="true">
					<div property="columns">
						<div type="indexcolumn" width="40">序号</div>
						<div type="checkcolumn" width="40"></div>
						<div field="workNo" headerAlign="center" width="80">工号</div>
						<div field="userName" headerAlign="center" width="80">姓名</div>
						<div field="sex" width="40" headerAlign="center" >性别</div>
						<div field="birthday" width="80" headerAlign="center" dateFormat="yyyy-MM-dd">出生日期</div>
						<div field="mobile" width="80" headerAlign="center" >手机号码</div>
						<div field="departName" width="80" headerAlign="center" >部门</div>
						<div field="enterTime" width="80" headerAlign="center" dateFormat="yyyy-MM-dd">入职日期</div>
						<div field="postName" headerAlign="center" width="80">职务名称</div>
						<div field="leaderName" headerAlign="center" width="80">直接领导</div>
						<div field="roleName" headerAlign="center" width="80">角色</div>
						<div field="status" headerAlign="center" width="50">状态</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	
	<div id="win" class="mini-window" title="新增用户" style="width:800px;height:440px;" showMaxButton="true" showCollapseButton="true" showShadow="true"
		showToolbar="true" showFooter="true" showModal="true" allowResize="true" allowDrag="true">
		<div id="inputForm" style="padding:10px;">
			<input name="userID" class="mini-hidden">
			<table align="center">
				<tr>
					<td align="right">用户姓名：</td>
					<td align="left"><input name="userName" class="mini-textbox" required="true"></td>
					<td align="right">登录名：</td>
					<td align="left"><input name="loginName" class="mini-textbox" required="true"/></td>
					<td align="right">登录密码：</td>
					<td align="left"><input name="loginPassword" class="mini-textbox" required="true"/></td>
				</tr>
				<tr>
					<td align="right" >性别：</td>
					<td align="left">
						<div class="mini-radiobuttonlist" repeatLayout="table"
							 name="sex"
							 textField="text" valueField="id" value="1"
							 data="[{id:1,text:'男'},{id:2,text:'女'}]" >
						</div>
					</td>
					<td align="right">手机号码：</td>
					<td align="left"><input name="mobile" class="mini-textbox" /></td>
					<td align="right">身份证号：</td>
					<td align="left"><input name="idCard" class="mini-textbox" /></td>
				</tr>
				<tr>
					<td align="right">工号：</td>
					<td align="left"><input name="workNo" class="mini-textbox" required="true"/></td>
					<td align="right">工种：</td>
					<td align="left"><input name="jobID" class="mini-combobox" textField="jobName" valueField="jobID" url="http.getUrl('/basic/workType/getWorkTypeListByMap.do')"></td>
					<td align="right">部门：</td>
					<td align="left"><input name="departID" id="depart" class="mini-combobox" textField="departName" valueField="departID" url="http.getUrl('/sys/depart/getDepartmentListByMap.do')" onvaluechanged="departChange"/></td>
				</tr>
				<tr>
					<td align="right">领导姓名：</td>
					<td align="left"><input name="leaderID" id="leader" class="mini-combobox" /></td>
					<td align="right">职务：</td>
					<td align="left"><input name="postName" class="mini-textbox" /></td>
					<td align="right">角色：</td>
					<td align="left"><input name="roleID" class="mini-combobox" textField="roleName" valueField="roleID" url="http.getUrl('/role/list.do')"/></td>
				</tr>
				<tr>
					<td align="right">邮箱：</td>
					<td align="left"><input name="email" class="mini-textbox" /></td>
					<td align="right">生日：</td>
					<td align="left"><input name="birthday" class="mini-datepicker" format="yyyy-MM-dd" /></td>
					<td align="right">学历：</td>
					<td align="left"><input name="education" class="mini-combobox" data="CONST.get('educationTypes')" textField="text" valueField="id" value="1"/></td>
				</tr>
				<tr>
					<td align="right">国家：</td>
					<td align="left"><input name="country" class="mini-textbox"></td>
					<td align="right">省份：</td>
					<td align="left"><input name="province" class="mini-textbox" /></td>
					<td align="right">城市：</td>
					<td align="left"><input name="city" class="mini-textbox" /></td>
				</tr>
				<tr>
					<td align="right">详细地址：</td>
					<td align="left" colspan="3"><input name="address" class="mini-textbox" style="width:400px;"/></td>
				</tr>
				<tr>
					<td align="right">建行帐号：</td>
					<td align="left"><input name="ccbAccount" class="mini-textbox"></td>
					<td align="right">交行帐号：</td>
					<td align="left"><input name="bccAccount" class="mini-textbox" /></td>
				</tr>
				<tr>
					<td align="right">公积金帐号：</td>
					<td align="left"><input name="fundAccount" class="mini-textbox" /></td>
					<td align="right">公积金状态：</td>
					<td align="left"><input name="fundState" class="mini-combobox" data="[{id:1,text:'正常'},{id:2,text:'封存'}]" value="1"/></td>
					<td align="right">入职日期：</td>
					<td align="left"><input name="enterTime" class="mini-datepicker" format="yyyy-MM-dd" required="true"></td>
				</tr>
				<tr>
					<td align="right">异常联系电话：</td>
					<td align="left"><input name="abnormalTel" class="mini-textbox"></td>
					<td align="right">状态：</td>
					<td align="left"><input name="status" class="mini-combobox" data="CONST.get('onJobState')" textField="text" valueField="id" value="1"/></td>
					<td align="right">离职日期：</td>
					<td align="left"><input name="leaveTime" class="mini-datepicker" format="yyyy-MM-dd"></td>
				</tr>
				<tr>
					<td align="right">备注：</td>
					<td align="left" colspan="3"><input name="remark" class="mini-textarea" style="width:400px;" vtype="maxLength:200"/></td>
				</tr>
			</table>
		</div>
		<div property="footer" style="text-align:center;padding:5px;padding-right:15px;">
			<a class="mini-button" iconCls="icon-save" onClick="inputAction()">保存</a>
			<a class="mini-button" iconCls="icon-cancel" onClick="miniui.hide('inputWin')">取消</a>
		</div>
	</div>

</body>

<script type="text/javascript">

	miniInit();

	// 如果不是管理员，则不能修改用户的角色身份
	var showEdit = false;
	var localUser = mini.decode(localStorage.getItem('user'));
	if (localUser != null) {
		if (localUser.userName == "admin") {
			showEdit = true;
		}
	}
	if (showEdit == false) {
		$("#btnEdit").hide();
	}

	var tree = mini.get("pageTree");
	var queryForm = new mini.Form("#queryForm");
	var datagrid = mini.get("datagrid"); // 表定义列表
	datagrid.set({
		url: http.getUrl("/user/page.do")
	});
	datagrid.load();

	// 加载浅蓝色背景和去除滚动条
	$('.mini-splitter').addClass('bg');
	//$('.fieldset-body-body').addClass('bg');

	tree.url = http.getUrl("/sys/depart/list.do");
	tree.load(tree.url);

	var editNode = null; // 当前编辑的节点
	/*********************************************************
	 * 左侧目录树的鼠标点击事件
	 *********************************************************/
	tree.on("nodedblclick", function (e) {
		// debugger
		editNode = e.node;
		tree.loadNode(editNode);
		if (editNode) {
			search();
		}
	});

	function departChange(){
		var departID = mini.get("depart").getValue();
		var urlcomb = mini.get("leader");
		urlcomb.setEnabled(true);
		urlcomb.setValueField("userID");
		urlcomb.setTextField("userName");
		urlcomb.set({
			url: http.getUrl("/user/getUserListByDepart.do?departID="+departID)
		});
	}

	function search() {
		var data = queryForm.getData(true, false);
		var node = tree.getSelectedNode();
		if (node) {
			data["departID"] = node.departID;
			data["departID_link"] = "like";
		}
		data.orderBy = "workNo";
		datagrid.load(data, null, miniui.showLoadErrorMessageBox);
	}

	datagrid.on("drawcell",function(e) {
		var record = e.record, column = e.column, field = e.field, value = e.value;
		if(field=="status"&&value!=null){
			if(value==1){
				e.cellHtml = "在职";
			}else{
				e.cellHtml = "离职";
			}
		}
		if(field=="sex"&&value!=null){
			if(value==1){
				e.cellHtml = "男";
			}else{
				e.cellHtml = "女";
			}
		}
		if (field == "workNo") {
			e.cellHtml = '<a  href="javascript:void(0);" onclick="openDetail(\''+record.userID+'\',\''+record.userName+'\');" style="text-decoration:none;">' + value + '</a>';
		}

	});

	/*********************************************************
	 * 操作方法
	 *********************************************************/
	var inputForm = new mini.Form("#inputForm");
	var win = mini.get("win");

	function input() {
		setTimeout(function () {
			inputForm.reset();
			win.showAtPos('center', 'middle');

		}, 100);
	}

	function inputAction() {
		if (inputForm.validate()) {
			miniui.mask("数据保存中...");
			var data = inputForm.getData(true, false);
			http.post("/user/save.do", data, function (page) {
				mini.unmask();
				win.hide();
				datagrid.reload();
				miniui.showSuccessTip("保存成功");
			});
		}
	}

	function edit() {
		inputForm.clear();
		var row = datagrid.getSelected();
		if (row) {
			inputForm.setData(row);
			win.showAtPos('center', 'middle');
		}else{
			miniui.showErrorMessageBox("请先选择要编辑的用户！");
			return;
		}

		inputForm.setData(row);
		win.showAtPos('center', 'middle');
	}

	// 更换直接领导
	function openLeaderDialog() {
		mini.open({
			url: ctx + '/page/system/win_user_select.html',
			title: "选择员工",
			width: 650,
			height: 550,
			onload: function () { },
			ondestroy: function (action) {
				if (action == "ok") {
					var iframe = this.getIFrameEl();
					var data = iframe.contentWindow.getData();
					data = mini.clone(data); //必须
					// console.log(data);
					mini.get("leaderName").setValue(data.userName);
					mini.get("leaderID").setValue(data.userID);
				}
			}
		});
	}

	// 更换部门
	function openDepartDialog() {
		mini.open({
			url: ctx + '/page/system/depart_select.html',
			title: "选择部门",
			width: 650,
			height: 550,
			onload: function () { },
			ondestroy: function (action) {
				if (action == "ok") {
					var iframe = this.getIFrameEl();
					var data = iframe.contentWindow.getData();
					data = mini.clone(data);
					mini.get("departName").setValue(data.departName);
					mini.get("departID").setValue(data.departID);
				}
			}
		});
	}

	function doBatchSave() {
		miniui.mask("操作进行中...");
		var url = null;
		var data = batchSetForm.getData(true, false);
		// 如果是单个用户修改
		if (editType == 1) {
			url = "/user/save.do";
		}
		// 如果是批量修改
		else {
			url = "/user/batchUpdate.do";
			var rows = datagrid.getSelecteds();
			if (rows.length == 0) {
				miniui.showErrorMessageBox("请先选择要批量修改的用户！");
				return;
			}
			var ids = common.getListKeys(rows, "userID");
			data.ids = ids;
			// data.userID = null;
			delete data.userID;
		}
		console.log(data);
		http.post(url, data, function (page) {
			mini.unmask();
			if (page.success) {
				miniui.showInfoMessageBox(page.message);
				miniui.hide("batchEditPanel");
				datagrid.reload();
			} else {
				miniui.showErrorMessageBox(page.message);
			}
		});
	}

	function openDetail(id,name){
		window.parent.mini.open({
			url:ctx +"/page/system/user_info.html?userID="+id,
			title: name,
			width: 1100,
			height: 520,
			ondestroy: function (action) {

			}
		});
	}

</script>

</html>